1613B - Absent Remainder - CodeForces Solution


greedy implementation sortings *1000

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    n=int(input())
    arr=list(map(int,input().split()))
    arr.sort()
    num=arr[0]
    cnt=0
    for i in range(1,n):
        cnt+=1
        ar=[]
        ar.append(arr[i])
        ar.append(num)
        if cnt>n//2:
            break
        print(*ar)

C++ Code:

                        #include <vector>
                        #include <iostream>
                        #include <map>
                        #include <math.h>
                        #include <algorithm>
                        #include <string>
                        #include <iomanip>
                        #include <stack>

                        #define ll long long
                        using namespace std;
                        template<typename _Tp>
                        istream& operator >> (istream& i, vector<_Tp>& v){
                          for(_Tp& x : v)
                            i >> x;
                          return i;
                        }

                        long long roundup(long long a, long long b){
                            if(a%b == 0){
                                return a/b;
                            }
                            else return (a/b)+1;
                        }
                        int oproundup(int a, int b){
                          if(a%b == 0){
                            return (a/b)+1;
                          }
                          else return (a/b)+1;
                        }

                        bool isprime(ll n){ //QUICKEST WAY TO DETERMINE IF A NUMBER IS PRIME OR NOT
                        if(n == 2){
                          return true;
                        }
                        if(n == 1){
                          return false;
                        }
                            for(ll i = 2; i < sqrt(n)+1; i++){
                                if(n%i==0) return false;
                            }
                            return true;
                        }
                        long long gcd(long long int a, long long int b)
                        {
                          if (b == 0)
                            return a;
                          return gcd(b, a % b);
                        }

                        // Function to return LCM of two numbers
                        long long lcm(long long a, long long b)
                        {
                            return (a / gcd(a, b)) * b;
                        }
                        int addallup(double n){

                            return (roundup(n,2)*(2 + (n - 1)));
                        }
                        void output(bool t){
                          if(t == false){
                            cout << "NO";
                          }
                          else cout << "YES";
                        }
                        map<char,int> mp;
                        map<int,map<char,int>> maps;
                        int factorial(int n){
                          int ans = 1;
                          for(int i = 1; i <= n; i++){
                            ans*=i;
                          }
                          return ans;
                        }
                        string to_lower(string s){
                          for(int i = 0; i < s.length(); i++){
                            if(s[i] >= 'a'){
                              s[i] =  (s[i]-32);
                            }
                          }
                          return s;
                        }
                         int getfull(char c, int leng){
                              string s;
                              for(int i = 0; i < leng; i++){
                                   s+=c;
                              }
                              return stoi(s);
                         }
                         string bin(long n)
                      {
                        long i;
                        string s;
                        s+='0';
                        for (i = 1 << 30; i > 0; i = i / 2)
                        {
                          if((n & i) != 0)
                          {
                            s+='1';
                          }
                          else
                          {
                            s+='0';
                          }
                        }
                        return s;
                      }
                      int binaryToDecimal(string n)
                    {
                        string num = n;
                        int dec_value = 0;

                        // Initializing base value to 1, i.e 2^0
                        int base = 1;

                        int len = num.length();
                        for (int i = len - 1; i >= 0; i--) {
                            if (num[i] == '1')
                                dec_value += base;
                            base = base * 2;
                        }

                        return dec_value;
                    }
                    void s(vector<int> v){
                        sort(v.begin(), v.end());
                    }

                    bool issquare(int n){
                      if(floor(sqrt(n)) == sqrt(n)) return true;


                      return false;
                    }
                    #define read(n) cin >> n;
                    long long int fast_exp(int base, int exp)
                    {
                        if(exp==1)
                        return base;
                        else
                        {
                            if(exp%2 == 0)
                            {
                                long long int base1 = pow(fast_exp(base, exp/2),2);
                                if(base1 >= 1000000007)
                                return base1%1000000007;
                                else
                                return base1;
                            }
                            else
                            {
                                long long int ans = (base*  pow(fast_exp(base,(exp-1)/2),2));
                                if(ans >= 1000000007)
                                return ans%1000000007;
                                else
                                return ans;
                            }
                        }
                    }

                    ll xorupton(ll x){
                        ll xxor = 0;
                        if(x%4 == 1){
                                xxor = 1;
                            }
                            else if(x%4 == 2){
                                xxor = x+1;
                            }
                            else if(x%4==3){
                                xxor = 0;
                            }
                            else xxor = x;
                        return xxor;
                    }
                    #define read2(n,m) cin >> n >> m;
                      void solve(int tt){
                            int n;
                            cin >> n;
                            vector<int> v;
                            map<int,bool> mp;
                            for(int i = 0; i < n; i++){
                                int x;
                                cin >> x;
                                v.push_back(x);
                                mp[x]=1;
                            }
                            int buff = 0;
                            sort(v.rbegin(), v.rend());
                            for(int i = 0; i < v.size()/2; i++){
                                cout << v[i] << " " << v[v.size() - 1] << "\n";
                            }
                        }


                      int main(){
                         int t = 1;
                         cin >> t;
                         int x = 1;
                         while(t--){
                              solve(x);
                              x++;
                         }
                      }


Comments

Submit
0 Comments
More Questions

981A - Antipalindrome
365A - Good Number
1204B - Mislove Has Lost an Array
1409D - Decrease the Sum of Digits
1476E - Pattern Matching
1107A - Digits Sequence Dividing
1348A - Phoenix and Balance
1343B - Balanced Array
1186A - Vus the Cossack and a Contest
1494A - ABC String
1606A - AB Balance
1658C - Shinju and the Lost Permutation
1547C - Pair Programming
550A - Two Substrings
797B - Odd sum
1093A - Dice Rolling
1360B - Honest Coach
1399C - Boats Competition
1609C - Complex Market Analysis
1657E - Star MST
1143B - Nirvana
1285A - Mezo Playing Zoma
919B - Perfect Number
894A - QAQ
1551A - Polycarp and Coins
313A - Ilya and Bank Account
1469A - Regular Bracket Sequence
919C - Seat Arrangements
1634A - Reverse and Concatenate
1619C - Wrong Addition